function [ PercentageRatio, ClassificationOutput ] = SvmECOC( DataSet, Gamma )

HammingDistance = @(a,b)sum(a(:)~=b(:));

[Samples, Labels, Classes] = LoadTrainData(DataSet);

CodeMatrix = BuildECOC(Classes);

MatrixSize = size(CodeMatrix);
Functions = MatrixSize(2);

SamplesSize = size(Samples);
SamplesCount = SamplesSize(2);

TransformedLabels = zeros(Functions, SamplesCount);

%Transformacja etykiet.
for i = 1:1:Functions
    for j = 1:1:SamplesCount
        TransformedLabels(i, j) = CodeMatrix(Labels(j), i);
    end
end

AlphaY = cell(1, Functions);
SVs = cell(1, Functions);
Bias = cell(1, Functions);
Parameters = cell(1, Functions);
nSV = cell(1, Functions);
nLabel = cell(1, Functions);

%Uczenie na podstawie przetransformowanych etykiet.
for i = 1:1:Functions
    [AlphaY{i}, SVs{i}, Bias{i}, Parameters{i}, nSV{i}, nLabel{i}] = RbfSVC(Samples, TransformedLabels(i, :), Gamma);
end

[Samples, Labels] = LoadTestData(DataSet);

SamplesSize = size(Samples);
SamplesCount = SamplesSize(2);

PredictedCodes = zeros(Functions, SamplesCount);
DecisionValues = zeros(Functions, SamplesCount);

for i = 1:1:Functions
    [PredictedCodes(i, :), DecisionValues(i, :)] = SVMClass(Samples, AlphaY{i}, SVs{i}, Bias{i}, Parameters{i}, nSV{i}, nLabel{i});
end

PredictedLabels = PredictedCodes';
ClassRatio = zeros(SamplesCount, Classes);

for s = 1:1:SamplesCount
    for i = 1:1:Classes
        ClassRatio(s, i) = HammingDistance(PredictedLabels(s, :), CodeMatrix(i, :));
    end
end

TotalHitCount = 0;
ClassificationOutput = zeros(1, SamplesCount);

for s = 1:1:SamplesCount
    [C, I] = min(ClassRatio(s, :));
    ClassificationOutput(s) = I;
end

for s = 1:1:SamplesCount
    if ClassificationOutput(s) == Labels(s)
        TotalHitCount = TotalHitCount + 1;
    end
end

PercentageRatio = (TotalHitCount/SamplesCount)*100;

end

